package com.dragee;

import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

/**
 * @author tys on 11/16/20
 */
@Component
public class MyApplicationRunner implements ApplicationRunner {
    /*
    控制台输入时下位机接受到消息
    * */
//    public static void main(String[] args) throws IOException {
//        Socket socket = new Socket("10.229.36.78", 8999);
//        // 为了让用户自己输入消息
//        Scanner scanner = new Scanner(System.in);
//        OutputStream outputStream = socket.getOutputStream();
//        while (scanner.hasNext()) {
//            outputStream.write(scanner.nextLine().getBytes());
//        }
//        outputStream.close();
//        socket.close();
//    }

    /*
    作为客户端 接受服务端消息
    * */
//    public static void main(String[] args) throws IOException {
//        Socket socket = new Socket("10.229.36.78", 8999);
//        InputStream inputStream = socket.getInputStream();
//        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
//        int len = 0;
//        byte[] buffer = new byte[1024];
//        while ((len = inputStream.read(buffer))!= -1) {
//            String accept = new String(buffer, 0, len);
//            P.green("接受到消息：" + accept);
//            P.yellow(accept);
//        }
//    }



    @Override
    public void run(ApplicationArguments args) throws Exception {
        System.out.println("------------------启动完成-------------------");
    }
}
